
com.sxnsx.xnaja.ui.prompt = function () {
    var pub = {};
    var priv = {};
    this.download_method = "";
    this.save_path="";
    
    this.method_radio_cb = function (flag){
        this.download_method = flag? "directly": "get_links";
    };

    this.chk_form = function(){
        var util = xnaja_app.utilities;
        var page_from = parseInt((util.$('page_from_menulist').value));
        var page_to = parseInt((util.$('page_to_menulist').value));
        var err_str = "";
        var err_num = 0;

        if (isNaN(page_from)) {
            err_num = 1;
            err_str = "err_page_from_not_int_alert";
        }
        if (isNaN(page_to)) {
            err_num = 2;
            err_str = "err_page_to_not_int_alert";
        }
        if (page_to < page_from && (page_from != -1 || page_from != -1)) {
            err_num = 3;
            err_str = "err_page_from_larger_alert";
        }
        if (err_num != 0)
            err_str = util.get_local_string(err_str)
        return [err_num, err_str];
    };

    this.do_ok = function(){
        var util = xnaja_app.utilities;

        var ret = this.chk_form();
        var errno = ret[0];
        var msg = ret[1];

        if (1<=errno && errno <=3 ) {
            alert(util.get_local_string("err_chk_field_alert") + "\n" + msg);
            return false;
        } 

        if (this.download_method != "get_links") {
            this.save_path = util.select_save_to_dir();
            if (this.save_path == "") {
                return false;
            }
        }

        window.arguments[0].page_from = util.$('page_from_menulist').value;
        window.arguments[0].page_to = util.$('page_to_menulist').value;
        window.arguments[0].photo_size = 
            util.$('photo_size_menulist').selectedItem == null? []: 
                util.$('photo_size_menulist').selectedItem.value;
        window.arguments[0].download_method = this.download_method;
        window.arguments[0].save_path = this.save_path; 
        window.arguments[0].accepted = 1;
        return true;
    };

    this.do_cancel = function(){
        window.arguments[0].accepted = 0;
        return;
    };

    this.load = function () {
        var util = xnaja_app.utilities;
        util.$('xnaja_download_prompt').width = 500;
        util.$('xnaja_download_prompt').height = 300;

        util.$('url_addr_box').value = window.arguments[0].url_addr;
        util.$('page_from_menulist').value = window.arguments[0].page_from;
        util.$('page_to_menulist').value = window.arguments[0].page_to;
        if (window.arguments[0].photo_size.length == 0) {
            util.$('photo_size_row').style.display = "none";
        } else {
            util.$('photo_size_row').style.display = "block";
            util.$("photo_size_menulist").removeAllItems()
            for (var each in window.arguments[0].photo_size) {
                label_and_val = window.arguments[0].photo_size[each];
                util.$('photo_size_menulist').appendItem(label_and_val, label_and_val)
            }
            util.$("photo_size_menulist").selectedItem = util.$("photo_size_menulist").getItemAtIndex(0);
        }
        if (window.arguments[0].download_method == "get_links") {
            util.$("method_radiogroup").selectedIndex = 1;
        } else {
            util.$("method_radiogroup").selectedIndex = 0;
        }

        this.download_method = window.arguments[0].download_method;

    };
};
com.sxnsx.cexport(com.sxnsx.xnaja.ui.prompt);

